import pandas as pd
from matplotlib import pyplot as plt
df = pd.read_excel('女装销售数据.xlsx')
plt.rcParams['font.sans-serif'] = 'SimHei'
df['历史总订单数（单）'] = df['历史总订单数（单）'].apply(lambda x:x if type(x)!=str else x.replace('+','')).astype('int')
df_new = df[df['历史总订单数（单）'] ==1]
df_old = df[df['历史总订单数（单）'] >1]
plt.figure()
data = [df_new.index.size,df_old.index.size]
plt.pie(data,labels=['新客户','老客户'],autopct='%.2f%%')
plt.title('新老客户人数占比饼状图')
plt.show()



#
plt.figure()
data = [df_new['总交易金额（元）'].sum(),df_old['总交易金额（元）'].sum()]
plt.pie(data,labels=['新客户','老客户'],autopct='%.2f%%')
plt.title('新老客户总交易金额占比饼状图')
plt.show()

#
x = ['新客户','老客户']
h1 =df_new['总交易金额（元）'].sum() / df_new.index.size
h2 =df_old['总交易金额（元）'].sum() / df_old.index.size
height = [h1,h2]
plt.bar(x,height,width=0.3)
plt.ylabel('客单价/元')
plt.title('新老客户客单价柱状图')
for a,b in zip(x,height):
    plt.text(a,b,'%.1f' %b,ha='center')
plt.show()







